using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using Intelsi.Entity;

namespace Intelsi.DataAccess.Mapping
{
    public class ProveedorMap : EntityTypeConfiguration<Proveedor>
    {
        public ProveedorMap()
        {
            // Primary Key
            this.HasKey(t => t.IdProvedor);

            // Properties
            this.Property(t => t.Ruc)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(11);

            this.Property(t => t.RazonSocial)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Email)
                .IsRequired()
                .HasMaxLength(350);

            this.Property(t => t.NombreContacto)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.DNIContacto)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(8);

            this.Property(t => t.Direccion)
                .IsRequired()
                .HasMaxLength(200);

            this.Property(t => t.TelefonoEmpr)
                .IsRequired()
                .HasMaxLength(15);

            this.Property(t => t.TelefonoCont)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.TelefonoContII)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Proveedor");
            this.Property(t => t.IdProvedor).HasColumnName("IdProvedor");
            this.Property(t => t.Ruc).HasColumnName("Ruc");
            this.Property(t => t.RazonSocial).HasColumnName("RazonSocial");
            this.Property(t => t.Email).HasColumnName("Email");
            this.Property(t => t.IdUbigeo).HasColumnName("IdUbigeo");
            this.Property(t => t.NombreContacto).HasColumnName("NombreContacto");
            this.Property(t => t.DNIContacto).HasColumnName("DNIContacto");
            this.Property(t => t.Direccion).HasColumnName("Direccion");
            this.Property(t => t.TelefonoEmpr).HasColumnName("TelefonoEmpr");
            this.Property(t => t.TelefonoCont).HasColumnName("TelefonoCont");
            this.Property(t => t.TelefonoContII).HasColumnName("TelefonoContII");

            // Relationships
            this.HasRequired(t => t.ubigeo)
                .WithMany(t => t.Proveedors)
                .HasForeignKey(d => d.IdUbigeo);

        }
    }
}
